package com.ruoyi.club.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.club.domain.CmsClubPhoto;
import com.ruoyi.club.service.ICmsClubPhotoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 俱乐部场馆照片Controller
 * 
 * @author miki
 * @date 2024-10-01
 */
@Controller
@RequestMapping("/club/photo")
public class CmsClubPhotoController extends BaseController
{
    private String prefix = "club/photo";

    @Autowired
    private ICmsClubPhotoService cmsClubPhotoService;

    @RequiresPermissions("club:photo:view")
    @GetMapping()
    public String photo()
    {
        return prefix + "/photo";
    }

    /**
     * 查询俱乐部场馆照片列表
     */
    @RequiresPermissions("club:photo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsClubPhoto cmsClubPhoto)
    {
        startPage();
        List<CmsClubPhoto> list = cmsClubPhotoService.selectCmsClubPhotoList(cmsClubPhoto);
        return getDataTable(list);
    }

    /**
     * 导出俱乐部场馆照片列表
     */
    @RequiresPermissions("club:photo:export")
    @Log(title = "俱乐部场馆照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsClubPhoto cmsClubPhoto)
    {
        List<CmsClubPhoto> list = cmsClubPhotoService.selectCmsClubPhotoList(cmsClubPhoto);
        ExcelUtil<CmsClubPhoto> util = new ExcelUtil<CmsClubPhoto>(CmsClubPhoto.class);
        return util.exportExcel(list, "俱乐部场馆照片数据");
    }

    /**
     * 新增俱乐部场馆照片
     */
    @GetMapping("/add/{clubId}")
    public String add(@PathVariable("clubId") Long clubId, ModelMap mmap)
    {
        mmap.put("clubId",clubId);
        return prefix + "/add";
    }

    /**
     * 新增保存俱乐部场馆照片
     */
    @RequiresPermissions("club:photo:add")
    @Log(title = "俱乐部场馆照片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsClubPhoto cmsClubPhoto)
    {
        return toAjax(cmsClubPhotoService.insertCmsClubPhoto(cmsClubPhoto));
    }

    /**
     * 修改俱乐部场馆照片
     */
    @GetMapping("/edit/{imgId}")
    public String edit(@PathVariable("imgId") Long imgId, ModelMap mmap)
    {
        CmsClubPhoto cmsClubPhoto = cmsClubPhotoService.selectCmsClubPhotoById(imgId);
        mmap.put("cmsClubPhoto", cmsClubPhoto);
        return prefix + "/edit";
    }

    /**
     * 修改保存俱乐部场馆照片
     */
    @RequiresPermissions("club:photo:edit")
    @Log(title = "俱乐部场馆照片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsClubPhoto cmsClubPhoto)
    {
        return toAjax(cmsClubPhotoService.updateCmsClubPhoto(cmsClubPhoto));
    }

    /**
     * 删除俱乐部场馆照片
     */
    @RequiresPermissions("club:photo:remove")
    @Log(title = "俱乐部场馆照片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsClubPhotoService.deleteCmsClubPhotoByIds(ids));
    }
}
